package com.deep.auth.config;

import com.deep.auth.annotation.ApiController;
import com.deep.auth.model.properties.ApiPathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web配置类
 *
 * @author Deep
 * @date 2022/2/4
 */
@Configuration
public class MallWebConfig implements WebMvcConfigurer {

    @Autowired
    private ApiPathProperties apiPathProperties;

    /**
     * 视图控制器（试图映射可以方便页面跳转（省略controller里面的方法））
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/api/auth/login.html").setViewName("login");
//        registry.addViewController("/auth/login/login.html").setViewName("login");
        registry.addViewController("/api/auth/reg.html").setViewName("reg");
//        registry.addViewController("/auth/login/reg.html").setViewName("reg");
    }

    /**
     * 请求路径统一管理
     */
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer
                .addPathPrefix(apiPathProperties.getGlobalPrefix(), c -> c.isAnnotationPresent(ApiController.class));
    }
}

